from django.contrib import admin
from .models import LeaveRequest


@admin.register(LeaveRequest)
class LeaveRequestAdmin(admin.ModelAdmin):
    # 在列表页显示的字段
    list_display = (
        'student_name',
        'student_id',
        'teacher_name',
        'leave_request_type',
        'start_time',
        'end_time',
        'if_or_school',
        'if_or_city'
    )

    # 添加搜索功能
    search_fields = ('student_name', 'student_id', 'teacher_name', 'leave_request_type')

    # 添加过滤功能
    list_filter = ('leave_request_type', 'if_or_school', 'if_or_city', 'start_time', 'end_time')

    # 按日期排序
    ordering = ('-start_time',)

    # 在详情页中分组显示字段
    fieldsets = (
        ('基本信息', {
            'fields': ('student_name', 'student_id', 'teacher_name', 'phone_num')
        }),
        ('请假类型和时间', {
            'fields': ('leave_request_type', 'start_time', 'end_time')
        }),
        ('其他信息', {
            'fields': (
            'level', 'level_2', 'major', 'if_or_school', 'if_or_city', 'text_1', 'text_2', 'time_1', 'time_2')
        }),
    )
